package uitest
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.utils.setTimeout;
	import iscript.coreFramework.displays.drawing.LineSegment;
	import iscript.uiFramework.components.button.BaseButton;
	import iscript.uiFramework.components.button.FlatButton;
	import iscript.uiFramework.components.button.ImageButton;
	import iscript.uiFramework.components.layout.LayoutAlign;
	import iscript.uiFramework.components.layout.VBoxLayout;
	import iscript.uiFramework.components.message.Message;
	import iscript.uiFramework.components.message.MessageButtonType;
	import iscript.uiFramework.components.message.MessageType;
	import iscript.uiFramework.event.SilderEvent;
	import iscript.uiFramework.UIFramework;
	
	public class VBoxLayoutTest extends Sprite
	{
		private var vboxLt:VBoxLayout
		private var viewRect:Rectangle
		
		public function VBoxLayoutTest()
		{
			/* var b0:BaseButton = new BaseButton();
			   b0.textLabel.text = "hello"
			   b0.x = 200;
			   b0.y = 200;
			   b0.render(this);
			
			
			   var b1:BaseButton = new BaseButton();
			   b1.textLabel.text = "world"
			   b1.x = b0.x + b0.width;
			   b1.y = 200;
			 b1.render(this);*/
			
			viewRect = new Rectangle(20, 120, 400, 300);
			
			vboxLt = new VBoxLayout(viewRect);
			for (var i:int = 0; i < 3; i++)
			{
				var b0:BaseButton = new BaseButton();
				//var b0:FlatButton = new FlatButton();
				b0.text = "button" + i
			    b0.width = 100;
				b0.border = true;
				b0.render(this);
				b0.ClickHandler = function(e:BaseButton):void
				{
					addMessage()
				}
				
				//b0.theme = "MenuTheme"
				//b0.disabled = true;
				//b0.enabled = false; 
				vboxLt.addUIElement(b0);
			}
			vboxLt.space = 10;
			vboxLt.setAlign(LayoutAlign.CC)
			
			//vboxLt.addUIElement(b0)
			//vboxLt.addUIElement(b1)
			/*			 vboxLt.setAlign(LayoutAlign.TL)
			   vboxLt.setAlign(LayoutAlign.TC)
			   vboxLt.setAlign(LayoutAlign.TR)
			
			   vboxLt.setAlign(LayoutAlign.BL)
			   vboxLt.setAlign(LayoutAlign.BC)
			   vboxLt.setAlign(LayoutAlign.BR)
			
			   vboxLt.setAlign(LayoutAlign.CR)
			   vboxLt.setAlign(LayoutAlign.CC)
			 vboxLt.setAlign(LayoutAlign.CL)*/
			//vboxLt.space = 200;
			//vboxLt.offY = -50;
			vboxLt.updateRender();
			
	 
			
			var normal:BitmapData = UIFramework.resource.getBitmapData("GameLite.UIComponent.DefaultTheme.CloseButton.Normal");
			var down:BitmapData = UIFramework.resource.getBitmapData("GameLite.UIComponent.DefaultTheme.CloseButton.Down");
			var closeButton:ImageButton = new ImageButton(normal, down, down);
			closeButton.x = 100;
			closeButton.y = 100;
			closeButton.render(this);
			closeButton.ClickHandler = function():void
			{
				
				addMessage();
			
			}
			
			
			var  line:LineSegment = new LineSegment();
			line.thickness = 1;
			line.fillColor = 0xCE0067;
			line.drawRectangle(this.graphics,viewRect);
		
			//addEventListener (MouseEvent.CLICK, changePosition);
			//setTimeout (function ():void { }, 3000);
		}
		
		private function changePosition(e:MouseEvent):void
		{
			viewRect = new Rectangle(int(Math.random() * 600), int(Math.random() * 400), 700, 300);
			vboxLt.updateRender(viewRect);
			this.graphics.clear();
			var line:LineSegment = new LineSegment();
			line.thickness = 1;
			line.drawRectangle(this.graphics, viewRect);
		}
		
		private function addMessage():void
		{
			var msg:Message = new Message();
			
			msg.type = MessageType.INFO;
			msg.messageButtonConfig.type = MessageButtonType.YESNO
			msg.messageButtonConfig.YesButtonText = "确定"
			msg.messageButtonConfig.YesButtonHandler = function(e:BaseButton):void
			{
				trace(msg.text);
			}
			msg.title.text = "标签"
			msg.title.font = "微软雅黑"
			//msg.theme="GrayTheme"
			msg.text = "Are you sure you want to do that? 中文字符测试。"
			msg.render(this);
		
		}
	
	}

}